﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Game.Map;
using Game.Objects;
using Game.Types;

namespace GameEditor2.Toolbox
{
    public partial class InfrastructureItemControl : UserControl
    {
        Game.Objects.ObjectType _ObjectType;
        
        public InfrastructureItemControl()
        {
            InitializeComponent();
            
            SelectedInfrastructure.Selected += delegate 
            {
                this.UpdatePressedState();
            };
        }
        
        public Brush ToolColor
        {
            get { return this.button.Background; }
            set { this.button.Background=value; }
        }
        
        public ObjectType ObjectType
        {
            get { return _ObjectType; }
            set { _ObjectType= value; DisplayType(); }
        }
        
        void DisplayType()
        {
            if (_ObjectType != null)
            {
//                BitmapImage image = new BitmapImage();
//                image.BeginInit();
//                image.StreamSource = _ObjectType.Picture.Stream;
//                image.EndInit();
                this.buttonImage.Source = _ObjectType.Picture.WrappedObject as ImageSource;
            }
            else
            {
            }
        }
        
        void Button_Click(object sender, RoutedEventArgs e)
        {
            SelectedInfrastructure.ObjectType = _ObjectType;
        }
        
        void UpdatePressedState()
        {
            if (SelectedInfrastructure.ObjectType == _ObjectType)
            {
                this.button.Background=SystemColors.HighlightBrush;
            }
            else
            {
                this.button.Background=SystemColors.ControlLightBrush;
            }
        }
        
    }
}